package cn.zhuangcloud.newversion.common.kit;

import cn.zhuangcloud.newversion.common.model.Users;
import com.jfinal.plugin.redis.Redis;

public class TokenKit {

    private static final Users userDao = new Users().dao();
    public static String COOKIEID = "token";

    public static String getUsernameByToken(String token) {
        return token == null ? null : Redis.use().get(token);
    }

    public static Users getUserByToken(String token) {
        if (token == null) {
            return null;
        }
        return userDao.findFirst(userDao.getSqlPara("user.findByUsername", getUsernameByToken(token)));
    }

    public static void setToken(String username, String token) {
        Redis.use().setex(token, 3600, username);
    }

}
